package com.example.event_android

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import android.widget.Toast
import com.ohuang.eventbus.EventBus
import com.ohuang.eventbus.Subscribe

class MainActivity : AppCompatActivity() {
    var tv: TextView? = null
    var tv2:TextView?=null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        EventBus.get().register(this, this)
        tv = findViewById(R.id.test)
        tv2 = findViewById(R.id.test2)
        tv?.setOnClickListener {
            startActivity(Intent(this, MainActivity2::class.java))
        }
        tv2?.setOnClickListener {
            EventBus.get().postSticky("这是粘性事件")
        }
    }

    @Subscribe()
    fun aa(t: String) {
        tv?.text = t
    }


    override fun onDestroy() {
        super.onDestroy()
    }
}